<?php
if (empty($r['notes'])) {
?>
<div style="width:240px;">
	<div id="note-<?php echo $r['id_user']; ?>" style="display:none;">
		<button class="btn btn-info btn-mini" onclick="edit_notes(this);" data-uid="<?php echo $r['id_user']; ?>">
			<i class="icon-edit-alt"></i> 
		</button>
	</div>
	<div id="form-<?php echo $r['id_user']; ?>">
<?php
echo CHtml::form(Yii::app()->createUrl($this->id.'/'.$this->action->id), 'post', array('style'=>'margin-bottom:0;'));
echo CHtml::textArea('notes', '', array('rows'=>'3', 'style'=>'width:94%;'));
echo CHtml::hiddenField('uid', $r['id_user']);
echo CHtml::hiddenField('update', 1);
echo '<button class="btn btn-info btn-mini" onclick="submit_notes(this);return false;" data-uid="'.$r['id_user'].'">' . BUtils::T('confirm_btn') . '</button>';
echo CHtml::endForm();
?>
	</div>
</div>
<?php
} else {
	$notes = strip_tags($r['notes']);
?>
<div style="width:240px;">
	<div id="note-<?php echo $r['id_user']; ?>">
		<div style="height:88px;overflow:auto;"><?php echo $notes; ?></div>
		<hr class="hr4" />
		<button class="btn btn-info btn-mini" onclick="edit_notes(this);" data-uid="<?php echo $r['id_user']; ?>">
			<?php echo BUtils::T('edit_btn'); ?>
		</button>
	</div>
	<div id="form-<?php echo $r['id_user']; ?>" style="display:none;">
<?php
echo CHtml::form(Yii::app()->createUrl($this->id.'/'.$this->action->id), 'post', array('style'=>'margin-bottom:0;'));
echo CHtml::textArea('notes', $notes, array('rows'=>'3', 'style'=>'width:94%;'));
echo CHtml::hiddenField('uid', $r['id_user']);
echo CHtml::hiddenField('update', 1);
echo '<button class="btn btn-info btn-mini" onclick="submit_notes(this);return false;" data-uid="'.$r['id_user'].'">' . BUtils::T('confirm_btn') . '</button>';
echo CHtml::endForm();
?>
	</div>
</div>
<?php } ?>
<script>
$(function() {	
	//submit form
});
function edit_notes(e) {
	var uid = $(e).data('uid');
	$('#note-'+uid).hide();
	$('#form-'+uid).show();
}
function submit_notes(e) {
	var _this = $(e);
	var uid = _this.data('uid');
	var _form = _this.parents('form');
	var _url = _form.attr('action');
	$.ajax({
		'beforeSend':function(){
			$('#loader-temp, #response-temp').remove();
			_this.after(' <i id="loader-temp" class="icon-spinner icon-spin icon-large"></i>');
		},
		'error':function(obj){
			$('#loader-temp, #response-temp').remove();
			_this.before('<div id="response-temp" style="color:red;font-size:12px;margin-bottom:4px;">' + obj.responseText + '</div>');
		},
		'success':function(text){
			$('#yt0').trigger('click');//refresh the ajax list
			$('#loader-temp, #response-temp').remove();
			$('#form-'+uid).hide();
			$('#note-'+uid).show();
		},
		'type':'post',
		'url':_url,
		'cache':false,
		'data':_form.serialize()
	});
	return false;
}
</script>